
package com.repairService.core.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @ClassName: SpringContextUtils
 * @Description: Sping工具类
 * @author yangsong
 * @version V1.0.0
 */
@Component
public class SpringContextUtils implements ApplicationContextAware {

	/** Spring上下文对象 */
	private static ApplicationContext applicationContext;

	public SpringContextUtils() {
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		SpringContextUtils.applicationContext = applicationContext;
	}

	public ApplicationContext getApplicationContext() {
		return applicationContext;
	}

	public static <T> T getBean(Class<T> bean) {
		return applicationContext.getBean(bean);
	}

	public static Object getBean(String beanName) {
		return applicationContext.getBean(beanName);
	}
}
